import type { ProTableProps } from './typing'
import { useSettingColumn } from '@/components/tables/pro-table/basic-table/composables/setting-column'

/**
 * @FILENAME:  context.ts
 *  @Description:  // 依赖注入
 * @Author: ellwood
 * @CreateDate: 2024/11/7 - 13:43
 * @Version: V1.0.0
 */
const tableState = (props: ProTableProps) => {
  const columns = computed(() => props.columns)
  const options = computed(() => props.options)
  const settingColumn = useSettingColumn(props)

  return { columns, options, settingColumn }
}

const [useProTableProvider, useProTableInject]
  = createInjectionState(tableState)

export const useProTableState = (): ReturnType<typeof tableState> => {
  return (
    useProTableInject() ?? {
      columns: computed(() => []),
      options: computed(() => ({ reload: true, setting: true })),
      settingColumn: {} as any,
    }
  )
}

export { useProTableProvider }
